/*******************************************************************************
 * Initialize application load
 */
function initApplication() {

	$(document).ready(
			function() {
				/***************************************************************
				 * Needed as Modernizer loading is hindering window adEvent
				 * Listener;
				 */
				Rico.windowLoaded();
				SwiftUI.windowLoaded();
				/*
				 * Need to find solution for above problem.
				 */

				SwiftUI.enableLogging();
				SwiftUI.log("Init Called");
				
				//SwiftUI.createUploadComponent("test");
				$.jgrid.no_legacy_api = true;
				$.jgrid.useJSON = true;

				// Handler used inplace of JQuery $
				try {
					var mydate = new Date();
					identifier = identifier + mydate.getFullYear()
							+ mydate.getMonth() + mydate.getDay()
							+ mydate.getHours() + mydate.getSeconds()
							+ mydate.getUTCMilliseconds();
				} catch (e) {
				}

				Rico.loadModule('LiveGridForms', 'Calendar', 'Tree');

				/**
				 * Load Framework application classes Commented as it is not
				 * being executed...Instead loaded using modernizr
				 */
				// SwiftUI.loadModule('UIDesigner', 'UIperspective');
				SwiftUI.onLoad(function() {
					// Create perspective
					var perspective = new SwiftUI.UIPerspective({});
					SwiftUI.setPerspective(perspective);
					perspective.loadCenterTabs();

					// $("#cover").show();

					/**
					 * Hide all elements so that they can be displayed once
					 * layout is set
					 */
					$(".ui-layout-west").hide();
					$(".ui-layout-east").hide();
					$(".ui-layout-north").hide();
					$(".ui-layout-south").hide();
					$("#mainContent").hide();

					// Get Encryption Keys
					getKeys();

					// SwiftUI.getPerspective().loadOrSelectTab("center",1,"events.xml");
				});
			});

}

/*******************************************************************************
 * Modernizer settings to load all libs...
 ******************************************************************************/
Modernizr
		.load([
				/*
				 * { load :
				 * "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" }, {
				 * load :
				 * "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" }, {
				 * load : "lib/tiny_mce/jquery.tinymce.js" }, { load :
				 * "lib/dash.js" },
				 */
			
				{
					load : "assets/framework/css/login.css"
				/* DEMO styles - specific to this page */
				},
				{
					load : "assets/jquery/layout/css/complex.css"
				},
				{
					load : "assets/jquery/themeroller/themes/base/jquery-ui.css"
				},
				{
					load : "assets/jqgrid/css/ui.jqgrid.css"
				},
				{
					load : "assets/jqgrid/css/ui.multiselect.css"
				},
				{
					load : 'assets/ricoClient/css/rico.css'
				},
				{
					load : "assets/dhtmlxScheduler/dhtmlxscheduler.css"
				/*
				 * }, { load: "assets/jquery.dform-0.1.3/doc/styles/main.css"
				 */
				/*
				 * [if lte IE 7]> <style type="text/css"> body { font-size:
				 * 100%; } </style> <![endif]
				 */
				},
				{
					load : "assets/jQuery-Validation-Engine/css/validationEngine.jquery.css"
				},
				{
					load : "assets/jquery-fileupload/css/jquery.fileupload-ui.css"
				},
				/*
				 * { load : "assets/formLayout/css/cssFormStyles.css" },
				 */
				/* Code below this lines is Javascript Includes */
				{
					load : "assets/framework/js/variables.js"
				/* DEMO scripts - specific to this page */
				},
				{
					load : "assets/jquery/layout/js/complex.js"
				/* REQUIRED scripts for layout widget */
				},
				{
					load : "assets/jquery/jquery-1.7.js"
				},
				{
					load : "assets/jquery/jquery-ui-1.8.2.custom.min.js"
				},
				{
					load : "assets/jstree/jquery.cookie.js"
				},
				{
					load : "assets/jstree/jquery.hotkeys.js"
				},
				{
					load : "assets/jstree/jstree.js"
				},
				{
					load : "assets/jquery/layout/jquery.layout.js"
				/*
				 * }, { load:
				 * "assets/jquery.dform-0.1.3/jquery.dform-0.1.3.min.js"
				 */
				/* For Form Css */
				},
				{
					load : "assets/framework/js/enhanceForm.js"
				/* For Form Validation */
				},
				{
					load : "assets/jQuery-Validation-Engine/js/languages/jquery.validationEngine-en.js"
				},
				{
					load : "assets/jQuery-Validation-Engine/js/jquery.validationEngine.js"
				},
				{
					load : "assets/jquery/jquery.timers-1.0.0.js"
				},
				{
					load : "assets/jquery/themeroller/themeswitchertool/js/mythemeswitcher.js"
				},
				{
					load : "assets/jcryption/jquery.jcryption-1.1.min.js"
				},
				{
					load : "assets/framework/js/framework.js"
				},
				{
					load : "assets/jqgrid/js/i18n/grid.locale-en.js"

				},
				{
					load : "assets/jqgrid/plugins/ui.multiselect.js"
				},
				{
					load : "assets/jqgrid/js/jquery.jqGrid.min.js"
				},
				{
					load : 'assets/ricoClient/js/rico.js'
				},
				{
					load : 'assets/ricoClient/js/rico2jQuery.js'
				},
				{
					load : 'assets/ricoClient/js/translations/ricoLocale_en.js'
				},
				{
					load : 'assets/ricoClient/js/ricoUI.js'
				},
				{
					load : 'assets/ricoClient/js/ricoThemeroller.js'
				},
				{
					load : "assets/SwiftUIClient/js/SwiftUI.js"
				},
				{
					load : "assets/SwiftUIClient/js/SwiftUI2jQuery.js"
				},
				{
					load : "assets/SwiftUIClient/js/i18n/SwiftUILocale_en.js"
				},
				{
					load : "assets/SwiftUIClient/js/SwiftUIDesignComponent.js"
				},
				{
					load : "assets/SwiftUIClient/js/SwiftUIPerspective.js"
				},
				{
					load : "assets/dhtmlxScheduler/dhtmlxscheduler.js"
				},
				{
					load : "assets/dhtmlxScheduler/ext/dhtmlxscheduler_units.js"
				},
				{
					load : "assets/dhtmlxScheduler/ext/dhtmlxscheduler_map_view.js"
				},
				{
					load : "assets/dhtmlxScheduler/ext/dhtmlxscheduler_minical.js"
				},
				{
					load : "assets/dhtmlxScheduler/ext/dhtmlxscheduler_collision.js"
				/*
				 * The Templates plugin is included to render the
				 * upload/download listings
				 */
				},
				{
					load : "assets/tinymce/jscripts/tiny_mce/jquery.tinymce.js"
				},

				{
					load : "assets/jquery-fileupload/js/tmpl.min.js"
				/*
				 * Bootstrap JS and Bootstrap Image Gallery are not required,
				 * but included for the demo
				 */
				},
				{
					load : "assets/jquery-fileupload/js/bootstrap.min.js"
				/*
				 * The Iframe Transport is required for browsers without support
				 * for XHR file uploads
				 */
				},
				{
					load : "assets/jquery-fileupload/js/jquery.iframe-transport.js"
				/* The basic File Upload plugin */
				},
				{
					load : "assets/jquery-fileupload/js/jquery.fileupload.js"
				/* The File Upload file processing plugin */
				},
				{
					load : "assets/jquery-fileupload/js/jquery.fileupload-fp.js"
				/* The File Upload user interface plugin */
				},
				{
					load : "assets/jquery-fileupload/js/jquery.fileupload-ui.js",
					complete : function() {
						/*
						 * Run this after everything in this group has
						 * downloaded and executed, as well everything in all
						 * previous groups
						 */
						initApplication();
					}
				} ]);
